Skip to content

Conversation

@notimaginative
Copy link
Contributor

Make the move from SDL2 to SDL3 along with fixes and improvements made along the way. (long-term draft PR)

@notimaginative notimaginative added refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability library A feature or issue related to third-party libraries labels May 27, 2025
@notimaginative
Copy link
Contributor Author

All existing features should be in working order now, though only limited testing was done to confirm that. Additional tweaks are likely. The main exception is setting of gamma, which has been removed from SDL3. This will need to be handled by shaders instead.

Look for TODO: SDL3 comments in the code for any notable issue or change that may need to be addressed in the future.

This PR will also see bigger refactors to make use of SDL3's new audio and filesystem code. Proper gamepad support and working multi voice chat are also likely. Those changes should be self-contained feature commits which may eventually be split into separate PRs or just dropped entirely.

WARNING: This PR will be rebased, squashed, and reordered many times before it's done. So if you follow it locally then please plan accordingly.

@notimaginative
Copy link
Contributor Author

Regarding audio changes, the SDL3 audio system will be used everywhere. OpenAL is still used for sound effects, but only for mixing, with the result being fed to SDL3 for actual playback. That feature requires the loopback device extension from openal-soft and will fall back to regular physical device access if it's not available. Aside from the init changes there is no real change necessary to normal OpenAL code. That allows further work to the OpenAL code to be done without having to really know about the SDL3 stuff. And since sound effects are the only bit of code using OpenAL, it's now possible to use all of MAX_CHANNELS for sound effects instead of having to reserve channels for other sections of code.

Note that flags and config info are unchanged to preserve max compatibility with older builds. Choosing a specific playback/recording device in settings or via the launcher will work like it always has, yet will have no effect with this new code.

The physical device fallback code could be removed if we start requiring openal-soft as opposed to it being optional. openal-soft is distributed with all official builds and our prebuilt version is already required for Windows and Mac builds. It's only optional for Linux builds, however nearly all distros distribute openal-soft as their only openal version.

There are two main benefits to this new setup: 1) the SDL3 audio code is much simpler, and 2) when the default audio device changes it will switch automatically.

The first allows for much cleaner and easier to understand code if no special mixing is required. Movies, audio streaming, and audio capture do not require 2D/3D positioning effects, so using OpenAL for them is overkill.

The second means that if you are playing FSO and audio is coming out of your computer speakers, but then you turn on/plug in some headphones, the audio will switch to the new device automatically. This also means that selecting a specific device to use generally isn't required as SDL3 will automatically switch to whatever device is considered default at the OS level. It should all just work in other words, without any special configuration or interaction by the user.

At the moment EFX/EAX effects via the play-sound-from-file sexp do not work. That sexp uses audiostr, which no longer uses OpenAL, so the effects don't work (though the sound will still play without EFX). An easy workaround for that is not available, but a refactoring of the code is possible should the desire from modders for that capability warrant it.

Voice capture is also not complete. The code has been rewritten to use SDL3 instead of OpenAL, however it remains unusable as there is no compression codec in place to allow it to work with multi. Once that issue has been sorted out the changes will be submitted.

@notimaginative notimaginative force-pushed the move_to_sdl3 branch 4 times, most recently from 248090b to eed4643 Compare July 22, 2025 08:05
@notimaginative notimaginative force-pushed the move_to_sdl3 branch 2 times, most recently from 4ac1a50 to 8297407 Compare August 2, 2025 03:49
@notimaginative notimaginative force-pushed the move_to_sdl3 branch 3 times, most recently from 573ad7a to 6d920fd Compare August 11, 2025 15:21
@notimaginative notimaginative force-pushed the move_to_sdl3 branch 4 times, most recently from df47b26 to f31f2f1 Compare August 20, 2025 02:32
@notimaginative notimaginative force-pushed the move_to_sdl3 branch 2 times, most recently from 8b44648 to ff31bec Compare October 17, 2025 07:19
@notimaginative
Copy link
Contributor Author

The commit got squashed down at some point, but this does partially address #4748. Specifically, it only enables textinput when a retail ui inputbox has focus, and disables textinput when it loses focus, which is proper usage. ImGui also uses it appropriately.

We still need to verify that rocketui enables it only while an input field has focus, and that the input fields lose focus when the debug console becomes active. Confirming that, or making changes to that affect, should fully resolve the issue.

@notimaginative notimaginative force-pushed the move_to_sdl3 branch 2 times, most recently from b2cf4fe to 6c37993 Compare November 22, 2025 15:23
Also updates imgui and related addons to newest versions
Continue using OpenAL for mixing, but feed the result to SDL3 for playback
rather than having OpenAL with the physical audio device. Outside of the minor
init changes OpenAL can be used as normal.

Bug fix: when querying the default playback device openal-soft will always
return "OpenAL Soft". So instead use the all_device_specifier if supported
(which it will be in this case) to get the proper default device name.
 - replace a lot of platform specific code with SDL filesystem functions
 - remove support for memory-mapped files (not actually used)
 - only do special case-sensitive filesystem handling if required
 - support case-sensitive roots on Windows
Additionally sets in-game FF options to use the same defaults as the old
osreg calls and makes changes take immediate effect (no restart required).
FF strength slider changed from float to integer type.
Allots special buttons for use by gamepad triggers. This allows triggers to be
usable as an axis or a button depending on the control type.

NOTE: This is implemented in a way that shouldn't break compatiblity with
other builds using the same cc profile. It does not use the control config code
that appears to allow for axis buttons due to it not being fully implemented
and needing too much work for sort out. Should that ever happen this feature
should be revisited so that it can be implemented properly.
 - generate appimage for qtfred if it's available
 - separate fso and qtfred install roots
 - move fso appimage files out of global space
 - fix qtfred appimage launch script
 - prefer X11 Qt backend for qtfred
Fix issue setting path cmake variables in the gui due to the incorrect
type being specified.
@notimaginative notimaginative force-pushed the move_to_sdl3 branch 2 times, most recently from 46ae64f to 8151608 Compare December 8, 2025 10:08
Clang treats -Og the same as -O1, which prevents the viewing of many variables
while debugging, so we need to use -O0 directly.
Use a callback for SDL3 to request more audio data instead of using a timer to
push audio data. Helps prevent issue with stall recovery when program execution
temporarily halts (like when debugging).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

library A feature or issue related to third-party libraries refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant